package de.bensoft.jrail.client.ui.trackplan.deflectoradmin;


import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.stage.Stage;
import de.bensoft.jrail.client.common.JavaFXController;
import de.bensoft.jrail.client.ui.controls.NumberField;
import de.bensoft.jrail.client.ui.trackplan.segments.DeflectorTrackSegment;

@JavaFXController(fxml="DeflectorAdmin.fxml")
public class DeflectorAdminController {
	
	// --------------------------------------------------------------------------------
	// INJECT
	// --------------------------------------------------------------------------------
	
	
	// --------------------------------------------------------------------------------
	// PUBLIC
	// --------------------------------------------------------------------------------
	private DeflectorTrackSegment deflectorSegment;
	public  DeflectorTrackSegment getDeflectorSegment() { return deflectorSegment; }
	public void setDeflectorSegment(DeflectorTrackSegment deflectorSegment) { this.deflectorSegment = deflectorSegment; initBindings(); }
	
	
	// --------------------------------------------------------------------------------
	// FXML
	// --------------------------------------------------------------------------------
	@FXML
	private NumberField nfAddress;
	
	@FXML
	private CheckBox cbxInvert;
	
	@FXML
	private CheckBox cbxStraight;
	
	@FXML
	private void initialize() {
		
	}
	
	@FXML
	private void onOk(ActionEvent ae) {
		deflectorSegment.getDeflectorInstance().save();
		((Stage)((Button)ae.getTarget()).getScene().getWindow()).close();
	}

	@FXML
	private void onCancel(ActionEvent ae) {
		((Stage)((Button)ae.getTarget()).getScene().getWindow()).close();
	}
	
	// --------------------------------------------------------------------------------
	// GUI
	// --------------------------------------------------------------------------------
	private void initBindings() {
		nfAddress.longProperty().bindBidirectional(deflectorSegment.getDeflectorInstance().addressProperty());
		cbxInvert.selectedProperty().bindBidirectional(deflectorSegment.getDeflectorInstance().invertProperty());
		cbxStraight.selectedProperty().bindBidirectional(deflectorSegment.getDeflectorInstance().straightProperty());
	}
}
